import java.util.Iterator;
import java.util.Stack;

/**
 * project5
 *
 * brief description of the program
 *
 * This program is released to public domain according to
 * author's wish, you can view full license at
 * http://tomatoeskit.org/upload/PublicDomainLicense.txt
 *
 * @author Fangning CHENG (Alpha.L Cheng) <chengf@purdue.edu>
 *
 * @lab section number 
 *
 * @date Oct 21, 2013
 *
 */

public class MyHistory implements Iterable<Shape>, History {
    private Stack<Shape> done   = new Stack<Shape>();
    private Stack<Shape> toRedo = new Stack<Shape>();
    
    public void add(Shape s)
    {
        done.push(s);
        toRedo.clear();
    }
    public void undo()
    {
        if (!done.isEmpty())
            toRedo.push(done.pop());
    }
    public void redo()
    {
        if (!toRedo.isEmpty())
            done.push(toRedo.pop());
    }
    public void clear()
    {
        done.clear();
        toRedo.clear();
    }
    public Iterator<Shape> iterator()
    {
        return done.iterator();
    }
    
}
